import java.util.Arrays;

public class test128 {
    public static int longestConsecutive(int[] nums) {
        if (nums.length <= 1) return nums.length;
        int[] array = Arrays.stream(nums).sorted().distinct().toArray();
        int len = 1, tempLen = 1;
        for (int i = 1; i < array.length; i++) {
            if (array[i] == array[i - 1] + 1) {
                len = Math.max(len, ++tempLen);
            } else {
                tempLen = 1;
            }
        }
        return len;
    }

    public static void main(String[] args) {
        //System.out.println(longestConsecutive(new int[]{100, 4, 200, 1, 3, 2}));
        System.out.println(longestConsecutive(new int[]{0, 3, 7, 2, 5, 8, 4, 6, 0, 1}));
        System.out.println(longestConsecutive(new int[]{1,2,0,1}));
    }
}
